package zkdemo;

import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Curator_JDK_Barrier {
	
	public static CyclicBarrier barrier = new CyclicBarrier(3);
	
	public static void main(String[] args) {
		ExecutorService excutor = Executors.newFixedThreadPool(3);
		
		excutor.submit(new Thread(() -> {
			System.out.println(Thread.currentThread().getName()+" ready");
			try {
				Curator_JDK_Barrier.barrier.await();
			} catch (Exception e) {
				e.printStackTrace();
			}
			System.out.println(Thread.currentThread().getName()+" go");
		}));
		excutor.submit(new Thread(() -> {
			System.out.println(Thread.currentThread().getName()+" ready");
			try {
				Curator_JDK_Barrier.barrier.await();
			} catch (Exception e) {
				e.printStackTrace();
			}
			System.out.println(Thread.currentThread().getName()+" go");
		}));
		excutor.submit(new Thread(() -> {
			System.out.println(Thread.currentThread().getName()+" ready");
			try {
				Curator_JDK_Barrier.barrier.await();
			} catch (Exception e) {
				e.printStackTrace();
			}
			System.out.println(Thread.currentThread().getName()+" go");
		}));
		
		excutor.shutdown();
	}
}
